import numpy as np
from GA import GA
from util import demo_func
import pandas as pd
import matplotlib.pyplot as plt

function = "sphere"
f = getattr(demo_func, function)

ga = GA(func=f, n_dim=50, size_pop=50, max_iter=800, lb=-1, ub=1, precision=1e-7)
best_x, best_y = ga.run()
print('best_x:', best_x, '\n', 'best_y:', best_y)
Y_history = pd.DataFrame(ga.all_history_Y)
# fig, ax = plt.subplots(2, 1)
# ax[0].plot(Y_history.index, Y_history.values, '.', color='red')
Y_history.min(axis=1).cummin().plot(kind='line')
plt.show()
